package com.qiyu.xujia.demo;

import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.io.File;
import java.util.Properties;

public class DemoEmail {
    public void sendMail() throws MessagingException {
        JavaMailSenderImpl sender = new JavaMailSenderImpl();
        sender.setHost("smtp.qiyucloud.com.cn");
        Properties properties = new Properties();
        properties.put("mail.stmp.auth",true);
        properties.put("mail.stmp.starttls.enable",true);
        sender.setJavaMailProperties(properties);
        sender.setUsername("jia.xu@qiyucloud.com.cn");
        sender.setPassword("Xj@20230710");


        MimeMessage message = sender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(message, true);
        helper.setFrom("jia.xu@qiyucloud.com.cn");
        helper.setTo("jia.xu@qiyucloud.com.cn");
        helper.setText("Thank you for ordering!");
        helper.addAttachment("xxxx.xlsx",new File("d:/接口测试.xlsx"));
        sender.send(message);
    }

    public static void main(String[] args) throws MessagingException {
        DemoEmail demoEmail = new DemoEmail();
        demoEmail.sendMail();
    }
}
